/**
 * 
 */
package com.geekteam.masterenglish.ui;

import java.io.IOException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.geekteam.masterenglish.R;
import com.geekteam.masterenglish.biz.LessionBiz;
import com.geekteam.masterenglish.entity.Album;
import com.geekteam.masterenglish.entity.Albums;
import com.geekteam.masterenglish.utils.JsonUtil;
import com.geekteam.masterenglish.utils.Utils;

/**
 * @author MTROL
 *
 */
public class SplashActivity extends Activity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		if(Utils.isDataBaseEmpty(this)){
			try {
				String response = JsonUtil.loadResourceJson(this, R.raw.album);
				Albums albums = (Albums) JsonUtil.fromJson(response, Albums.class);
				int size = albums.mAlbums.size();
				for(int i = 0; i<size; i++){
					Album album = albums.mAlbums.get(i);
					int numberLession = album.mLessions.size();
					for(int j = 0; j<numberLession; j++){
						album.mLessions.get(j).mCurrentTime = -1;
					}
					LessionBiz.processLession(this, album);
					Utils.updateFirstTimeUse(this, true);
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}else{
			Utils.updateFirstTimeUse(this, false);
		}
		
		/*DataRequest entity = new DataRequest();
		entity.id = "IWEE076I";
		entity.type = Constants.TYPE_PLAYLIST;
		
		Intent intent = new Intent();
		intent.putExtra(BundleKey.TYPE_REQUEST, TypeRequest.GET_DETAIL_LESSION);
		intent.putExtra(BundleKey.DATA_REQUEST, entity);
		intent.setClass(this, EEService.class);
		startService(intent);*/
		
		Intent intent = new Intent(this, MainActivity.class);
		startActivity(intent);
		finish();
	}
}
